package com.woniuxy.creditsystem.collectionmag.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.creditsystem.collectionmag.service.ICollectionService;
import com.woniuxy.creditsystem.common.bean.*;
import com.woniuxy.creditsystem.common.mapper.CollectionMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;


@Transactional(readOnly = true)
@Service
public class CollectionServiceImpl implements ICollectionService {


    @Resource
    private CollectionMapper collectionMapper;

    /**
     *
     * @param pageNum
     * @param pageSize
     * @param collectionFind
     * @return
     */
    @Override
    public PageInfo<CollectionInfo> findAllByParams(int pageNum, int pageSize, CollectionFind collectionFind) {
        return PageHelper.startPage(pageNum,pageSize).
                doSelectPageInfo(()->collectionMapper.findAllByParams(collectionFind));
    }


    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateCollectionInfo(CollectionInfo collectionInfo) {
        return collectionMapper.updateCollectionInfo(collectionInfo);
    }

    @Override
    public CollectionInfo getOneById(Long id) {
        return collectionMapper.getOneById(id);
    }

    @Override
    public CustomerInfo findRPIById(Long id) {
        return collectionMapper.findRPIById(id);
    }
}
